package com.shixi.shixitraining.shixitraining.ui.tabhome.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.TextView;

import com.shixi.shixitraining.shixitraining.R;
import com.shixi.shixitraining.shixitraining.ui.tabhome.entity.TrainingListDetailBean;
import com.shixi.shixitraining.shixitraining.view.recycleview.BaseAdapter;
import com.shixi.shixitraining.shixitraining.view.recycleview.BaseRecycleHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by shenyan on 2018/9/21.
 */
public class TrainingDateAdapter  extends BaseAdapter<TrainingListDetailBean.DataBean.DetailsBean> {
    private OnClickListener onClickListener;
    private List<Boolean> isClick = new ArrayList<>();

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }


    public TrainingDateAdapter(Context context, List<TrainingListDetailBean.DataBean.DetailsBean> data) {
        super(context, data);
    }

    @Override
    public void convert(final BaseRecycleHolder holder, final TrainingListDetailBean.DataBean.DetailsBean item, final int position) {

        holder.setText(R.id.training_date,item.getDate());
        holder.setText(R.id.training_price,item.getPrice());
        TextView mDate = holder.getView(R.id.training_date);
        TextView mPrice = holder.getView(R.id.training_price);

        if (onClickListener!=null){
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int Position = holder.getLayoutPosition();

                    if (isClick!=null&&isClick.size()>0){
                         for (int i=0;i<isClick.size();i++){

                                isClick.set(i,false);
                         }
                         isClick.set(Position,true);

                      notifyDataSetChanged();
                    }
                       onClickListener.setOnClickItemListener(v,Position);
                }
            });
        }


        if (isClick != null && isClick.size() > 0) {
            if (isClick.get(position)) {
                mDate.setTextColor(ContextCompat.getColor(mContext, R.color.red));
                mPrice.setTextColor(ContextCompat.getColor(mContext, R.color.red));
            } else {
                mDate.setTextColor(ContextCompat.getColor(mContext, R.color.black));
                mPrice.setTextColor(ContextCompat.getColor(mContext, R.color.black));
            }
        }




    }

    @Override
    protected int getLayoutId(int viewType) {
        return R.layout.adapter_training_date;
    }



    public interface OnClickListener {
        void setOnClickItemListener(View view, int position);
    }



}
